package controller

import (
	"context"
	"device-admin/config/redis"
	"device-admin/internal/app/web/crond"
	"device-admin/internal/define"
	"encoding/json"
	"time"

	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
)

type Report struct {
}

// HomePageReport 首页统计
func (Report) HomePageReport(c *gin.Context) {
	timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Second*3)
	defer cancel()
	res, err := redis.NewDB().HGet(timeoutCtx, define.HomePageReport, c.GetString("merchant_id")).Result()
	if err != nil {
		response.JSON(c, crond.DailyReport(c.GetString("merchant_id")), nil)
	} else {
		var ret map[string]interface{}
		json.Unmarshal([]byte(res), &ret)
		response.JSON(c, ret, nil)
	}
}
